<template>
  <div class="page-home">
    <!-- <van-nav-bar title="首页"/> -->
    <div class="p-t-15"></div>
    <van-swipe class="swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item,index) in swipeList" :key="index">
        <van-image :src="item.imgUrl" />
      </van-swipe-item>
    </van-swipe>
    <div class="nav-title">
      <h3>门诊服务</h3>
    </div>
    <div class="nav">
      <div :class="'item item-'+index" v-for="(item,index) in navList" :key="index" @click="$util.gotoPage(item.url)">
        <div class="title">
          <h3>{{item.name}}</h3>
          <p>{{item.tips}}</p>
        </div>
        <div class="icon">
          <van-icon :name="item.icon" size="36" />
        </div>
      </div>
    </div>
    <div class="nav-title">
      <h3>个人中心</h3>
    </div>
    <div class="menu fly-card no-border">
      <div :class="'item item-'+ index" v-for="(item,index) in menuList" :key="index" @click="$util.gotoPage(item.url)">
        <div class="thumb">
          <!-- <van-image :src="item.icon" /> -->
          <van-icon :name="item.icon" size="24" />
        </div>
        <div class="content">
          <div class="title">{{item.name}}</div>
          <div class="desc">{{item.desc}}</div>
        </div>
      </div>
    </div>
    <div class="login-out" v-if="access_token">
      <p class="c-grey align-center p-a-30" @click="loginOut">退出登录</p>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return {
      access_token: localStorage.getItem('access_token'),
      swipeList:[
        {id:1, imgUrl: this.$icon.banner1, url: ''},
        {id:1, imgUrl: this.$icon.banner2, url: ''},
        {id:1, imgUrl: this.$icon.banner3, url: ''},
      ],
      navList:[
        {name: '预约挂号', tips: '在线预约挂号', icon:'clock', url: '/patient/select?from=appointment'},
        {name: '门诊缴费', tips: '在线缴纳门诊费用', icon: 'gold-coin', url: '/pay/list'},
      ],
      menuList:[
        // {name: '自助缴费',icon: '#', desc: 'xxx'},
        // {name: '报告查询',icon: 'label', desc: 'xxx', url: '/report/index'},
        {name: '我的挂号',icon: 'todo-list-o', desc: '查看我的挂号记录', url: '/appointment/list'},
        {name: '就诊人管理',icon: 'user-o', desc: '管理就诊人信息', url: '/patient/list'},
      ]
    }
  },
  created(){
    if(this.$util.checkLogin('nologin')){
      this.$store.dispatch('getCurrentPatient');
    }
    // this.$store.dispatch('getCurrentPatient').then(res => {
    //   if(process.env.NODE_ENV == 'production'){
    //     this.$util.getWxCode('base');
    //   }else{
    //     // localStorage.setItem('openId', 'o8ijI5__7xesLlh6pR62XdG_6kt4');
    //   }
    // });
  },
  methods:{
    loginOut(){
      this.$dialog.confirm({
        title: '提示',
        message: '确定要退出登录？'
      }).then(() => {
        this.$http('delete', '/auth/token/logout', {}, (data,msg) => {
          localStorage.removeItem('access_token');
          this.$toast.success('已退出！');
          // this.$util.gotoPage('/login/index');  
          window.location.href = '/';
        });        
      }).catch(() => {

      })
    },
  }
}
</script>

<style>

</style>